#include "main/utils.h"
using namespace std;

int remainedLastNum(vector<int> vec, int step) {
  if (vec.empty() || step < 1) {
    return -1;
  }

  auto iter = vec.begin();
  while (vec.size() > 1) {
    for (int idx = 1; idx < step; ++idx) {
      ++iter;
      if (iter == vec.end()) {
        iter = vec.begin();
      }
    }
    iter = vec.erase(iter);
    if (iter == vec.end())
      iter = vec.begin();
  }

  return *iter;
}

int main() {
  vector<int> vec = {0, 1, 2, 3, 4};
  int step = 3;
  int ret = remainedLastNum(vec, step);
  cout << "remaining last number: " << ret << " expected: 3" << endl;

  return 0;
}
